/*

Author   : chaos

FileName : stl_fun_def.cpp

Date     : 17/08/17 17:40:01

*/
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

class Square
{
    public:
        template<class T> T operator() (T i) {return  i*i;}
};

template <class T>
class tmpSquare
{
    public:
        T operator() (T i) {return i*i;}
};

void print(int i ) {cout << i << " ";}
int main(int argc ,char *argv[])
{
    int a[] = {1,4,7,2,9,4,3};
    vector<int> v1(a,a+7), v2(v1.size()),v3(v1.size());

    cout << "transform element by function object ..."
        << endl << " v2 : ";
    transform(v1.begin() , v1.end() , v2.begin() ,Square());

    for_each(v2.begin(),v2.end() ,print);
    cout << endl << "transform element by template function object ... ";
    cout << endl << " v3 : " ;

    transform(v1.begin() , v1.end() ,v3.begin(),tmpSquare<int>());

    for_each(v3.begin() ,v3.end() ,print);
    cout << endl;


    return 0;

}
